public class attendance_page_test {

public Datetime transformed2{get; set;}
public Integer diference2{get; set;}
public Datetime finaldate2{get; set;}

public List<User> listUsers{get; set;}
public List<User> listUsers2{get; set;}
public List<Attendance_Record__c> listAttendance{get; set;}
public Integer count{get; set;}

public List<Personal_Time_Off__c> listTimeOff{get; set;}
public List<LoginHistory> loginToday{get; set;}
//public Boolean attendance{get; set;}
public Integer diference{get; set;}
public Datetime systemDate{get; set;}

    public attendance_page_test() {
    Datetime current = datetime.now(); // returns date time value in GMT time zone
    Date currDate = current.date();
    Time currTime = current.time();
    transformed2 = datetime.newinstancegmt(currDate,currTime);
    diference2 = current.hourgmt() - current.hour();
    finaldate2 = current.addHours(diference2);
    }
    
    public PageReference testeThis() {
    Datetime current = datetime.now();
    diference = current.hourgmt() - current.hour();
    systemDate = current.addHours(diference);
    listUsers=[SELECT Id, AccountId, Working_Hours__c, Attendance_Checked__c, Approved_Time_Off__c FROM User WHERE (AccountId != NULL) AND (Attendance_Checked__c = FALSE) AND (Approved_Time_Off__c = FALSE)];
    loginToday=[SELECT UserId, LoginTime, Status FROM LoginHistory WHERE LoginTime = TODAY];
    listTimeOff=[Select Name, Date__c, Number_Days__c, Employee__c, Approved__c, EndDate__c FROM Personal_Time_Off__c WHERE (Approved__c = TRUE) AND (EndDate__c >= TODAY)];
    List<Attendance_Record__c> attendanceList = new List<Attendance_Record__c>();
    for (User userTemp: listUsers)
    {
        for (LoginHistory log: loginToday)
        {
            if (userTemp.Id == log.UserId)
            {
                if (log.Status=='success')
                {
                    userTemp.Attendance_Checked__c = TRUE;
                }
            }
        }
        for (Personal_Time_Off__c timeOff: listTimeOff){
            if (timeOff.Employee__c == userTemp.AccountId)
            {
                userTemp.Approved_Time_Off__c = TRUE;
            }
        }    
    }
    update listUsers;
    listUsers2=[SELECT Id, Name, AccountId, Working_Hours__c, Attendance_Checked__c, Approved_Time_Off__c, Inattendance_On_7_Days__c FROM User WHERE (AccountId != NULL) AND (Attendance_Checked__c = FALSE) AND (Approved_Time_Off__c = FALSE)];
    for (User userTemp2: listUsers2)
    {
        attendanceList.add (new Attendance_Record__c(
             User__c = userTemp2.Id,
             Account_Id__c = userTemp2.AccountId,
             Employee_Name__c = userTemp2.Name,
             Date_of_inattendance__c = system.today()));
    }
    listUsers=[SELECT Id, Attendance_Checked__c, Approved_Time_Off__c FROM User WHERE (AccountId != NULL) AND ((Attendance_Checked__c = TRUE) OR (Approved_Time_Off__c = TRUE))];
    for (User userTemp3: listUsers)
    {
    userTemp3.Attendance_Checked__c = FALSE;
    userTemp3.Approved_Time_Off__c = FALSE;
    }
    insert attendanceList;
    update listUsers;
    listAttendance= [Select User__c, Date_of_inattendance__c, Account_Id__c FROM Attendance_Record__c WHERE Date_of_inattendance__c >= LAST_WEEK AND Excused_Absence__c = FALSE];
    for (User userTemp4: listUsers2)
    {
    count=0;
        for (Attendance_Record__c attendanceTemp: listAttendance)
        {
            if (attendanceTemp.Account_Id__c==userTemp4.AccountId)
            {
            count=count+1;
            }
        
        }
    userTemp4.Inattendance_On_7_Days__c=count;
    }
    update listUsers2;
    return null;
    }    

}